package cn.wizzer.app.web.modules.controllers.platform.user;

import cn.wizzer.app.user.modules.models.ChatReport;
import cn.wizzer.app.user.modules.models.vo.ChatReportVo;
import cn.wizzer.app.user.modules.services.ChatReportService;
import cn.wizzer.app.user.modules.services.UserService;
import cn.wizzer.framework.base.Result;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.dao.Chain;
import org.nutz.dao.Cnd;
import org.nutz.dao.Condition;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

@IocBean
@At("/platform/user/chat/report")
public class ReportController {

    @Inject
    @Reference
    private ChatReportService chatReportService;
    @Inject
    @Reference
    private UserService userService;


    @At("/")
    @Ok("beetl:/platform/user/chat/index.html")
    @RequiresPermissions("user.manager.chat.report")
    public void index() {

    }


    @At
    @Ok("json:full")
    @RequiresPermissions("user.manager.chat.report")
    public Object data(@Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize) {
        return Result.success().addData(chatReportService.listPage(pageNumber, pageSize));
    }
    @At("/do")
    @Ok("json:full")
    @RequiresPermissions("user.manager.chat.report.do")
    public Object doReport(@Param("id") String id, @Param("userId") String userId, @Param("flag") boolean flag) {
        if (flag){
            chatReportService.update(Chain.make("state",1),Cnd.NEW().where("id","=",id));
            userService.update(Chain.make("session_disabled",true),Cnd.NEW().where("id","=",userId));
        }else {
            chatReportService.update(Chain.make("state",2),Cnd.NEW().where("id","=",id));
        }
        return Result.success();
    }
//    user.manager.chat.report
//    user.manager.chat.report.do
}
